<template>
    <div class=" wrap-table user-p1 user-move">
        <div class="headerTop_ukl">
            <ul class="clearfix">
                <li>
                    <p class="p1"><img src="../../assets/images/icon_yanjiuduixiang.png" alt=""/><span>研究对象</span></p>
                    <p class="p3">{{userBasic.Surname}}({{userBasic.ResearchNo}})</p>
                </li>
                <li>
                    <p class="p1"><img src="../../assets/images/icon_ganyuzu.png" alt=""/>{{userBasic.GroupType |GroupType}}</p>
                    <p  class="p3" v-if="userBasic.Period!='3'"><span v-if="userBasic.GroupType==1">{{userBasic.IntensityOfIntervention |IntensityOfIntervention}}</span></p>
                    <p  class="p3" v-else><span v-if="userBasic.GroupType==1">{{userBasic.ChildIntensityOfIntervention |IntensityOfIntervention}}</span></p>
                </li>
                <li >
                    <p class="p1"><img src="../../assets/images/icon_huaiyunqi.png" alt=""/>{{userBasic.Period |Period}}</p>
                    <p class="p3"><span v-if="userBasic.Period==2">预产期：{{userBasic.ExpectedDate}},{{userBasic.PregnancyWeek}}</span></p>
                    <p class="p3"><span v-if="userBasic.Period==3">出生日期：{{userBasic.ChildBirthDate}},{{userBasic.ChildAge}}, {{userBasic.ChildSex|ChildSex}} </span></p>
                    <p class="p3"><span v-if="userBasic.Period==4">出生日期：{{userBasic.ChildBirthDate}},{{getChildAge2(userBasic.ChildBirthDate)}}, {{userBasic.ChildSex|ChildSex}} </span></p>
                </li>
            </ul>
        </div>
        <!---->
        <template>
            <el-table
                    :data="tableData"
                    border
                    v-loading="loading"
                    height="500"
                    element-loading-text="加载中"
                    style="width: 100%;">
                <el-table-column
                        prop="CreateTime"
                        align="center"
                        sortable
                        label="创建时间"
                        min-width="120">
                </el-table-column>
                <el-table-column
                        prop="Creater"
                        label="创建人"
                        align="center"
                        min-width="120">
                       
                </el-table-column>
                <el-table-column
                        prop="IsDraft"
                        label="状态"
                        align="center"
                        :formatter="UserStateFilter"
                        min-width="120">
                </el-table-column>
                <el-table-column
                        min-width="120"
                        align="center"
                        label="营养处方">
                    <template  slot-scope="scope">
                        <el-button size="small" v-if="scope.row.NutritionPrescriptionId==''" type="text">-</el-button>
                        <span  class="click_line"  v-else @click="handleTable(scope.row)"><span v-if="scope.row.IsDraft==0" class="click_line">修改</span><span v-else class="click_line">查看</span></span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="营养咨询CRF"
                        align="center"
                        min-width="120">
                    <template  slot-scope="scope">
                        <el-button v-if="scope.row.NutritionServiceId!==''" size="small" type="text"  @click="handleReport(scope.row)">查看</el-button>
                        <el-button v-else size="small" type="text">-</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </template>
        <!--分页-->
        <div class="block mg-20-auto">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="pageId"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
        <el-dialog title="营养处方" :visible.sync="dialogForm1" :append-to-body="true" top="0" width="60%" :close-on-click-modal="false">
                <div style="margin-right: 20px">
                    <div class="formX">
                        <!--<span style="color: #2DA3FB;margin-bottom: 5px;display: inline-block;cursor: pointer" @click="">复制以往营养处方</span>-->
                        <ul>
                            <li>
                                <h3>1.能量和宏量营养素（蛋白质，脂类，碳水化合物）摄入是否充足，比例是否适宜?</h3>
                                <el-select v-model="formx.Energy" placeholder="请选择" :disabled="Plis" style="width: 200px;margin:18px 0px 5px 0px;">
                                    <el-option label="是" value="1"></el-option>
                                    <el-option label="否" value="2"></el-option>
                                </el-select>
                                <p>详情:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.EnergyDetail">
                                </el-input>
                            </li>
                            <li>
                                <h3>2.各类食物摄入的种类和数量是否适宜?</h3>
                                <el-select v-model="formx.FoodCount" :disabled="Plis" placeholder="请选择" style="width: 200px;margin:18px 0px 5px 0px;">
                                    <el-option label="是" value="1"></el-option>
                                    <el-option label="否" value="2"></el-option>
                                </el-select>
                                <p>详情:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.FoodCountDetail">
                                </el-input>
                            </li>
                            <li>
                                <h3>3.主要微量营养素摄入是否充足，比例是否适宜? (钙，铁，碘，维生素A,叶酸)</h3>
                                <el-select v-model="formx.TraceElement" :disabled="Plis" placeholder="请选择" style="width: 200px;margin:18px 0px 5px 0px;">
                                    <el-option label="是" value="1"></el-option>
                                    <el-option label="否" value="2"></el-option>
                                </el-select>
                                <p>详情:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.TraceElementDetail">
                                </el-input>
                            </li>
                            <li>
                                <h3>4.饮食上存在的主要问题、误区?</h3>
                                <p>问题1:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.DietQuestion1">
                                </el-input>
                                <p>问题2(可选):</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.DietQuestion2">
                                </el-input>
                                <p>问题3(可选):</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.DietQuestion3">
                                </el-input>
                            </li>
                            <li>
                                <h3>5.建议</h3>
                                <p>建议1:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.Advice1">
                                </el-input>
                                <p>建议2(可选):</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.Advice2">
                                </el-input>
                                <p>建议3(可选):</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.Advice3">
                                </el-input>
                            </li>
                            <li>
                                <h3>6.营养师提供的资源</h3>
                                <el-checkbox-group v-model="labelList" :disabled="Plis" style="margin:18px 0px;" @change="changeLabellist">
                                    <el-checkbox label="中国居民平衡膳食餐盘"></el-checkbox>
                                    <el-checkbox label="膳食宝塔"></el-checkbox>
                                    <el-checkbox label="食谱"></el-checkbox>
                                    <el-checkbox label="其他" ></el-checkbox>
                                    <el-checkbox label="无"></el-checkbox>
                                </el-checkbox-group>
                                <p>详情:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.NurtritionResourcesDetail">
                                </el-input>
                            </li>
                        </ul>
                        </el-form>

                    </div>
                </div>
            <div slot="footer" class="dialog-footer" v-if="formx.IsDraft==0">
                <el-button @click="dialogForm1 = false">取 消</el-button>
                <el-button @click="submitForm(0)">保存草稿</el-button>
                <el-button type="primary" @click="submitForm(1)">提交</el-button>
            </div>
        </el-dialog>
        <el-dialog title="营养咨询CRF" :visible.sync="dialogFormAnli" :append-to-body="true" top="0" width="60%"
                   :close-on-click-modal="false">
                <div style="margin-right: 20px;overflow-x: hidden">
                    <!--<p>研究对象：{{formPoint.Surname}}({{formPoint.ResearchNo}})</p>-->
                    <!--<p>研究阶段：{{formPoint.Period |PeriodFilters}}</p>-->
                    <el-form :model="FormAnli" :rules="rules1" label-position="left" ref="FormAnli" label-width="60%" class="demo-ruleForm">
                        <el-form-item label="预约日期" prop="VistDate">
                            <el-date-picker
                                    v-model="FormAnli.VistDate"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="开始时间" prop="StartTime">
                            <el-time-picker
                                    v-model="FormAnli.StartTime"
                                    range-separator="-"
                                    value-format="HH:mm"
                                    format="HH:mm"
                                    placeholder="请选择">
                            </el-time-picker>
                        </el-form-item>
                        <el-form-item label="结束时间" prop="EndTime">
                            <el-time-picker
                                    v-model="FormAnli.EndTime"
                                    range-separator="-"
                                    format="HH:mm"
                                    value-format="HH:mm"
                                    placeholder="请选择">
                            </el-time-picker>
                        </el-form-item>
                        <el-form-item label="随访类型" prop="VisitType">
                            <el-select v-model="FormAnli.VisitType" placeholder="请选择" clearable>
                                <el-option label="营养咨询#1" value="1"></el-option>
                                <el-option label="随访" value="4"></el-option>
                                <el-option label="营养咨询#2" value="2"></el-option>
                                <el-option label="营养咨询#3" value="3"></el-option>

                            </el-select>
                        </el-form-item>
                        <p class="formPlebek">营养咨询前</p>
                        <el-form-item label="预览过研究对象的相关材料 (之前的营养报告，行动计划, 体重追踪记录, 健康现况表)?" prop="IsViewPriorData">
                            <el-select v-model="FormAnli.IsViewPriorData" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="与干预护士交流过研究对象的情况?" prop="IsChatWithNurse">
                            <el-select v-model="FormAnli.IsChatWithNurse" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <p class="formPlebek">营养咨询中</p>
                        <el-form-item label="谁陪研究对象一起来做营养咨询的？请勾选" prop="Companions">
                            <el-checkbox-group v-model="Companions" @change="changeCops">
                                <el-checkbox label="研究对象自己"></el-checkbox>
                                <el-checkbox label="丈夫/伴侣"></el-checkbox>
                                <el-checkbox label="母亲"></el-checkbox>
                                <el-checkbox label="婆婆"></el-checkbox>
                                <el-checkbox label="父亲"></el-checkbox>
                                <el-checkbox label="公公"></el-checkbox>
                                <el-checkbox label="其他"></el-checkbox>
                            </el-checkbox-group>
                            <el-input v-if="Companions.indexOf('其他')>-1" v-model="FormAnli.CompanionsOther"  placeholder="请输入内容"></el-input>
                        </el-form-item>
                        <el-form-item label="研究对象在就诊前已完成《3天饮食日记》 (3DD)?" prop="IsComplete3DD">
                            <el-select v-model="FormAnli.IsComplete3DD" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="没有完成3DD" prop="UnComplete3DDReason" >
                            <el-radio-group v-model="FormAnli.UnComplete3DDReason">
                                <el-radio label="忘记了">忘记了</el-radio>
                                <el-radio label="没有时间">没有时间</el-radio>
                                <el-radio label="太难了">太难了</el-radio>
                                <el-radio label="其他">其他</el-radio>
                            </el-radio-group>
                            <el-input v-if="FormAnli.UnComplete3DDReason=='其他'" v-model="FormAnli.UnComplete3DDReasonOther"  placeholder="请输入内容"></el-input>
                        </el-form-item>

                        <el-form-item label="与研究对象一起审阅和确认3DD的内容?" prop="IsTogetherView3DD">
                            <el-select v-model="FormAnli.IsTogetherView3DD" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="使用臻鼎“营养之星”录入了3DD?" prop="IsFillIn3DD">
                            <el-select v-model="FormAnli.IsFillIn3DD" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="有没有做《24小时膳食回顾》?" prop="IsReviewDiet">
                            <el-select v-model="FormAnli.IsReviewDiet" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="使用臻鼎“营养之星”录入了《24小时膳食回顾》？" prop="IsFillInDiet">
                            <el-select v-model="FormAnli.IsFillInDiet" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="《膳食评估报告》已生成并保存?" prop="IsSaveDietReport">
                            <el-select v-model="FormAnli.IsSaveDietReport" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="与研究对象一起审阅和确认《膳食评估报告》的内容?" prop="IsTogetherConfirmDietReport">
                            <el-select v-model="FormAnli.IsTogetherConfirmDietReport" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="《营养处方表》已完成" prop="IsCompleteNurtitionPrescription">
                            <el-select v-model="FormAnli.IsCompleteNurtitionPrescription" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="安排下一次营养咨询的时间?" prop="IsSetNextVisitDate">
                            <el-select v-model="FormAnli.IsSetNextVisitDate" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                                <el-option label="N/A" value="3"></el-option>
                            </el-select>
                        </el-form-item>
                        <p class="formPlebek">营养咨询结束后</p>
                        <el-form-item label="与干预护士交流了该研究对象的情况?" prop="IsCommunicationWithNurse">
                            <el-select v-model="FormAnli.IsCommunicationWithNurse" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <p style="margin:10px 0px;">其他意见</p>
                        <el-input
                                type="textarea"
                                :rows="3"
                                placeholder=""
                                v-model="FormAnli.OtherOpinion">
                        </el-input>
                    </el-form>
                </div>
        </el-dialog>
    </div>
</template>
<script>
import {mapGetters} from 'vuex'
import {getChildAge2} from '@/utils/index'
import {filterPeriod,filterIntensityOfIntervention} from '@/utils/localDic'
export default {
    name:'userP1',
    data() {
        return {
            tableData:[],
            pageId:1,
            total:null,
            loading:false,
            pageSize:10,
            dialogForm1:false,
            tableData1:[],
            pageId1:1,
            total1:null,
            loading1:true,
            pageSize1:10,
            itemType:'',
            sysId:'',
            researchNo:'',
            mobile:'',
            Plis:false,
            formx:{
                NurtritionResourcesDetail:'',
                NurtritionResources:'',
                Advice3:'',
                Advice2:'',
                Advice1:'',
                DietQuestion3:'',
                DietQuestion2:'',
                DietQuestion1:'',
                TraceElementDetail:'',
                TraceElement:'',
                FoodCountDetail:'',
                FoodCount:'',
                EnergyDetail:'',
                Energy:'',
            },
            userBasic:{
                Surname:'',
                ResearchNo:'',
                ExpectedDate:'',
                Period:'',
                IntensityOfIntervention:'',
                GroupType:''
            },
            changeVal:'混合显示模式',
            optionP: [{value: '母乳喂养', label: '母乳喂养'}, {value: '环境', label: '环境'}, {value: '营养', label: '营养'}, {value: '身体活动', label: '身体活动'}, {value: '心理健康', label: '心理健康'}, {value: '睡眠', label: '睡眠'}, {value: '吸烟', label: '吸烟'}],
            options: [{value: '0', label: '混合显示模式'}, {value: '1', label: '只显示频率问卷'},{value: '2', label: '只显示重要程度问卷'}],
            UserStateFilter(row, column, cellValue, index){
                return cellValue==1?'已发送':'草稿'
            },
            optionsNurse:[],
            labelList:[],
            onOFFsub:false,
            subDisabled:false,
            dialogFormAnli:false,
            FormAnli:{
                IsCommunicationWithNurse:'',
                        IsSetNextVisitDate:'',
                        IsCompleteNurtitionPrescription:'',
                        IsTogetherConfirmDietReport:'',
                        IsSaveDietReport:'',
                        IsFillInDiet:'',
                        IsReviewDiet:'',
                        IsFillIn3DD:'',
                        IsTogetherView3DD:'',
                        UnComplete3DDReason:'',
                        IsComplete3DD:'',
                        CompanionsOther:'',
                        Companions:'',
                        IsChatWithNurse:'',
                        IsViewPriorData:'',
                        VisitType:'',
                        EndTime:'',
                        StartTime:'',
                        VistDate:'',
                        OtherOpinion:''
            },
            rules1:{
                IsCommunicationWithNurse:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsSetNextVisitDate:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsCompleteNurtitionPrescription:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsTogetherConfirmDietReport:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsSaveDietReport:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsFillInDiet:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsReviewDiet:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsFillIn3DD:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsTogetherView3DD:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        UnComplete3DDReason:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsComplete3DD:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        CompanionsOther:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        Companions:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsChatWithNurse:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        IsViewPriorData:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        VisitType:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        EndTime:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        StartTime:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
                        VistDate:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
            },
            Companions:[],
            formPoint:{},
            dataRow:'',
            copyObject:''
        }
    },
    components:{
       
    },
    props:{
        changeIndex:{
            type: String,
        }
    },
    watch:{
        changeIndex:function(index){
            if(index=='5'){
                this.getList()
            }
        }
    },
    computed:{
        ...mapGetters([
                'resechObj',
                'userIcon',
                'userId',
                'token'
            ]),
        LASTTIME:function(){
            let dateAlary=new Date(this.userBasic.ExpectedDate)
            return new Date(dateForm(dateAlary.setMonth(dateAlary.getMonth()-9,dateAlary.getDate()-7)))
        },
        yunzhou:function(){
            return parseInt((WeeksBetw(new Date,this.LASTTIME))/7)
        },
        yuntianshu:function(){
            return parseInt((WeeksBetw(new Date,this.LASTTIME))%7)
        },
        birthWeek(){
            return parseInt((WeeksBetw(new Date,new Date(this.userBasic.ChildBirthDate)))/7)    
        },
        birthDay(){
            return parseInt((WeeksBetw(new Date,new Date(this.userBasic.ChildBirthDate)))%7)
        }
    },
    created() {
        
    },
    methods: {
         getChildAge2(val){ //获取儿童期2年龄
            return val && getChildAge2(val)
        },
        handleSizeChange(val) {       //条数改变
            this.pageSize=val;
            this.getList()
        },
        changeCops:function(val){
            this.FormAnli.Companions=val.join(',')
        },
        changeLabellist:function(val){   //多选
            this.formx.NurtritionResources=val.join(',')
        },
        handleReport:function(row){    //案例报告表
            let that=this;
            that.dialogFormAnli=true;
            that.Companions=[]
            that.rowOff=false
            that.dataRow=''
            that.formPoint={};
            that.FormAnli={
                IsCommunicationWithNurse:'',
                IsSetNextVisitDate:'',
                IsCompleteNurtitionPrescription:'',
                IsTogetherConfirmDietReport:'',
                IsSaveDietReport:'',
                IsFillInDiet:'',
                IsReviewDiet:'',
                IsFillIn3DD:'',
                IsTogetherView3DD:'',
                UnComplete3DDReason:'',
                IsComplete3DD:'',
                CompanionsOther:'',
                Companions:'',
                IsChatWithNurse:'',
                IsViewPriorData:'',
                VisitType:'',
                EndTime:'',
                StartTime:'',
                VistDate:'',
                OtherOpinion:''
            }
            that.formPoint=row
            console.log(that.formPoint)
            that.dataRow=row;
            that.$nextTick(function () {
                that.$refs['FormAnli'].resetFields();
            })
            that.FormAnli.ResearchObjectId=row.ResearchObjectId
            that.FormAnli.NutritionServiceId=row.NutritionServiceId
            that.service({
                url: "/ResearchObject/GetNurtritionCaseReport",
                method: "get",
                params: {
                    nutritionServiceId:row.NutritionServiceId
                }
            }).then(response => {
                if(response.dtData.length>0){
                    that.FormAnli=response.dtData[0]
                    that.Companions=(response.dtData[0].Companions||'').split(',')
                }
            }).catch(data => {

            });
        },
        handleTable:function(row){  //营养处方
            let that=this;
            that.dialogForm1=true;
            row.IsDraft=='1'?that.Plis=true:that.Plis=false
            that.onOFFsub=false;
            that.labelList=[]
            that.formx={
                IsDraft:'',
                NurtritionResourcesDetail:'',
                NurtritionResources:'',
                Advice3:'',
                Advice2:'',
                Advice1:'',
                DietQuestion3:'',
                DietQuestion2:'',
                DietQuestion1:'',
                TraceElementDetail:'',
                TraceElement:'',
                FoodCountDetail:'',
                FoodCount:'',
                EnergyDetail:'',
                Energy:'',
            }
            that.formx.ResearchObjectId=row.ResearchObjectId
            that.formx.NutritionServiceId=row.SYS_ID
            that.service({
                url: "/ResearchObject/GetNutritionPrescription",
                method: "get",
                params: {
                    sysId:row.SYS_ID
                }
            }).then(response => {
                if(response.dtData.length>0){
                    that.formx=response.dtData[0]
                    that.labelList=(response.dtData[0].NurtritionResources||'').split(',')
                }
            }).catch(data => {

            });
        },
        handleCurrentChange(val) {    //页数改变
            this.pageId = val
            this.getList()
        },
        GetNurse:function(){
            let that=this;
            that.service({
                url:'/Sys/GetNurse',
                method:'get',
                params:{
                    roleGroup:'5'
                }
            }).then(response=>{
                let options=response.dtData
                for(let i of options){    //处理姓名账号不一致，Nan
                i.Name=i.Name || ''
                let username=i.Surname+i.Name
                username=='undefined'?username=i.UserCode:username=username
                i.icons=username
            }
                that.optionsNurse=options;
            }).catch(data=>{

            })
        },
        handleSizeChange1(val) {       //条数改变11
            this.pageSize1=val;
            this.getList()
        },
        handleCurrentChange1(val) {    //页数改变11
            this.pageId1 = val
            this.getList()
        },
        addInfo:function(){  //添加
            this.dialogForm1=true
        },
        GetPlanFeedBack:function(){
            let that=this;
            that.loading1=true;
            that.service({
                url:'/ResearchObject/GetPlanFeedBack',
                method:'get',
                params:{
                    planId:that.formx.SYS_ID
                }
                }).then(response=>{
                    that.tableData1=response.dtData;
                    that.loading1=false
                }).catch(data=>{
                    that.loading1=false
            })
        },
        changeNurse:function(row,val){ //修改护士
            let that=this;
            var cid=that.optionsNurse.find(function (item) {
                return item.icons==val
            })
            row.CreaterId=cid.SYS_ID||''
            this.$confirm('是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.service({
                        url:'/ResearchObject/SaveNutritionPrescription',
                        method:'post',
                        data:{...row}
                        }).then(response=>{
                            that.getList()
                            that.$message({
                                message:'修改成功',
                                type:'success'
                            })
                    }).catch(data=>{
                })
            }).catch(() => {
                that.getList()
                that.$message({
                    message:'已取消',
                    type:'info'
                })

            });
        },
        submitForm:function(type){   //提交
            let that=this;
            if(that.onOFFsub){
                that.subDisabled=true
                return false;
            }
            that.onOFFsub=true
            if((this.formx.Energy==''||this.formx.EnergyDetail==''||this.formx.FoodCount==''||this.formx.FoodCountDetail==''||this.formx.TraceElement==''||this.formx.TraceElementDetail==''||this.formx.DietQuestion1==''||this.formx.Advice1==''||this.formx.NurtritionResources==''||this.formx.NurtritionResourcesDetail=='')&&(type==1)){
                that.$message({
                    message: '不是可选的选项，均为必填项',
                    type: 'warning'
                });
                that.onOFFsub=false;
                return false;
            }
            if((this.formx.Energy==undefined||this.formx.EnergyDetail==undefined||this.formx.FoodCount==undefined||this.formx.FoodCountDetail==undefined||this.formx.TraceElement==undefined||this.formx.TraceElementDetail==undefined||this.formx.DietQuestion1==undefined||this.formx.Advice1==undefined||this.formx.NurtritionResources==undefined||this.formx.NurtritionResourcesDetail==undefined)&&(type==1)){
                that.$message({
                    message: '不是可选的选项，均为必填项',
                    type: 'warning'
                });
                that.onOFFsub=false;
                return false;
            }
            setTimeout(()=>{
                that.service({
                    url:'/ResearchObject/SaveNutritionPrescription',
                    method:'post',
                    data:{
                ...that.formx,
                        IsDraft:type,
                        Creater:that.userIcon,
                        CreaterId:that.token,
                }}).then(response=>{
                    that.dialogForm1=false
                    that.getList()
                }).catch(data=>{
                    that.onOFFsub=false;
                    that.subDisabled=false
                })
            },200)
        },
        resultChange:function(val){  //状态评估
            let that=this;
            that.service({
                url:'/ResearchObject/SavePlan',
                method:'post',
                data:{
                    ResearchObjectId:that.sysId,
                    ...that.formx,
                    IsDraft:1,
                    Result:val
                }}).then(response=>{
                    that.dialogForm1=false
                    that.$message({
                        message:'修改成功',
                        type:'success'
                    })
                    that.getList()
                }).catch(data=>{
            })
        },

        getList:function(){           //获取一级信息列表
            let that=this
            that.userBasic=''
            if(that.resechObj.mobile ||that.resechObj.researchNo){
                that.sysId='';
                that.mobile=that.resechObj.mobile;
                that.researchNo=that.resechObj.researchNo;
            }
            that.service({
                url:'/ResearchObject/GetParticipantDetail',
                method:'get',
                params:{
                    itemType:'8',
                    sysId:'',
                    period:'',
                    researchObjectId:that.sysId,
                    mobile:that.mobile,
                    researchNo:that.researchNo,
                    pageCount:(that.pageId-1),
                    pageSize:that.pageSize,
                }
                }).then(response=>{
                    response.dtData.dtBasic[0]?that.userBasic=response.dtData.dtBasic[0]:''
                    that.tableData=response.dtData.dtPrescription;
                    that.total=parseInt(response.dtData.dtPrescription[0].TotalCount)

            }).catch(data=>{
            })
        },
    },
    mounted:function(){
        let that=this;
        that.sysId=that.$route.query.id;
        that.mobile=that.$route.query.mobile;
        that.researchNo=that.$route.query.researchNo;
        that.getList()
     //   that.GetNurse()
    },
    filters:{
        GroupType:function(val){
            if(val=='' ||val==undefined){
                return ''
            }
            return val=='1'?'A': 'B'
        },
         IntensityOfIntervention:function(val){
             return filterIntensityOfIntervention(val)
        },
        Period:function(val){
             return filterPeriod(val)
        },
        PeriodFilters(cellValue){
            return filterPeriod(cellValue)
        },
        ChildSex(val){
	        return val=='1'?'男':val=='2'?'女':'未知'
        }
    }
  }
function addZero(s){
    return s < 10 ? '0' + s: s;
}
function setDate(dataTime,n,m){
    var times=new Date(dataTime)
    times.setDate(times.getDate()+n+m*7); //增加一天
    return dateForm(times)
}
function dateForm(data){   //日期格式化
    return   new Date(data).getFullYear()+'-'+addZero((new Date(data).getMonth()+1))+'-'+addZero(new Date(data).getDate())
}
function WeeksBetw(date1,date2) {  //计算日期之间相差得天数
    var _dt1=new Date(date1);
    var _dt2=new Date(date2);
    var dt1=_dt1.getTime();
    var dt2=_dt2.getTime();
    return parseInt(Math.abs(dt1- dt2)/1000/60/60/24);//这里是计算天数,如果想获得周数则在该返回值上再除以7
}
</script>
<style scoped lang="scss">
    .user-p1{
        .headerTop{
            margin-bottom:30px;
            p{
                font-size:16px;
                margin-bottom: 15px;
                color:#303133;
            span{
                padding:10px;
            }
            .span1{
                margin-left: 25px;
            }
        }
    }
    .user-pi-ul{
        margin:0px auto 20px auto;
        li{
            float: left;
            width: 200px;
            margin-right: 20px;
        }
    }

    }
    .formX{
        .top{
            text-align: center;
        }
        ul{
            li{
                margin:20px;
                h3{
                    color: #606266;
                    font-weight: normal;
                    font-size: 17px;
                }
                h5{
                    font-weight: normal;
                    margin:5px 0;
                }
                p{
                    color: #999999;
                    margin-bottom: 10px;
                    margin:10px 0px;
                }
            }
        }
    }
    .headerTop_ukl{
        /*border:1px solid #EDF1F7;*/
        padding:5px 20px 10px 0px;
        min-width: 800px;
        width:1000px;
        font-size:14px;
    ul{
    li{
        float: left;
        margin-right: 50px;
    .p1{
        color:#999999;
        padding-bottom:5px;
        display: inline-block;
    img{
        display: inline-block;margin-right: 10px;
    };

    }
    .p3{
        display: inline-block;
        padding-left: 10px;
        color: #666;
    }
    }
    }
    }
    .isReadspan{cursor: pointer;color: #0066FF}
    .iconImg{width: 30px;height: 30px;}
    .click_line{cursor: pointer;color:#409EFF;}
</style>
